package cn.zzm.support.activeMQ;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * @program: study
 * @description: 模拟springMVC方式（非springboot方式） 实现request-response模式
 * @author: 周昭名
 * @create: 2019-04-10 17:50
 **/

@Component
public class ReplyTo {

    @Resource(name="jmsQueueTemplate")
    private JmsTemplate jmsTemplate;

    public void send(String responseMsg, Message producerMsg) throws JMSException {
        jmsTemplate.send(producerMsg.getJMSReplyTo(), new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
            Message message = session.createTextMessage(responseMsg);
            return message;
            }

        });
    }

}

